<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
                <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
                <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
            </div>
        </div>
    </div>
</div>
<!-- START 内容部分 -->
<div class="container" >
    <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
        <input type="hidden" name="createId" id="createId" value="${createId}">
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">shipment ID</label>
            <div class="col-sm-6">
                <input type="text" id="createShipmentId" name="createShipmentId"  class="form-control"  />
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">渠道</label>
            <div class="col-sm-6">
                <select id="createChannelName" name="createChannelName"  class="form-control">
                    <option value="">请选择</option>
                    <%for(var dict in channel){%>
                    <option value="${dict.channelName}">${dict.channelName}</option>
                    <%}%>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">SKU</label>
            <div class="col-sm-6">
                <div class="input-group">
                    <input type="text" id="createSku" name="createSku" class="form-control">
                    <span class="input-group-btn">
                        <button type="button" class="search-product btn btn-primary">搜索</button>
                    </span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">FNSKU</label>
            <div class="col-sm-6">
                <input type="text" id="createFnSku" name="createFnSku" readonly="readonly" class="form-control"  />
            </div>
        </div>
        <div>
            <div class="form-group">
                <label class="col-sm-2 control-label text-right">产品名称</label>
                <div class="col-sm-6">
                    <input type="text"  disabled="disabled" id="relatedProductName" name="relatedProductName"  class="form-control" />
                </div>
            </div>
        </div>
        <div>
            <div class="form-group">
                <label class="col-sm-2 control-label text-right">Listing</label>
                <div class="col-sm-6">
                    <input type="text" readonly id="createListing" name="createListing"  class="form-control" />
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">数量</label>
            <div class="col-sm-6">
                <input type="text" id="createNumber" name="createNumber" class="form-control" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">装箱量</label>
            <div class="col-sm-6">
                <input type="text" id="createPackage" name="createPackage" class="form-control" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">外箱长</label>
            <div class="col-sm-6">
                <input type="text" id="createBoxLength" name="createBoxLength" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">外箱宽</label>
            <div class="col-sm-6">
                <input type="text" id="createBoxWeight" name="createBoxWeight" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">外箱高</label>
            <div class="col-sm-6">
                <input type="text" id="createBoxHeight" name="createBoxHeight" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">单箱体积</label>
            <div class="col-sm-6">
                <input type="text" id="createVolume" name="createVolume" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">单箱毛重</label>
            <div class="col-sm-6">
                <input type="text" id="createWeight" name="createWeight" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">供应商</label>
            <div class="col-sm-6">
                <select id="createSupplierId"  name="createSupplierId"  class="form-control" xm-select="createSupplierId" xm-select-radio xm-select-search>
                    <option value=""></option>
                    <%for(var dict in supplier){%>
                    <option value="${dict.supplierName}">${dict.supplierName}</option>
                    <%}%>
                </select>
                <input type="hidden" id="createSupplierName"value="" name="createSupplierName">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">仓库</label>
            <div class="col-sm-6">
                <select id="createWareId"  name="createWareId"  class="form-control" xm-select="createWareId" xm-select-radio xm-select-search>
                    <option value=""></option>
                    <%for(var dict in ware){%>
                    <option value="${dict.detailName}">${dict.detailName}</option>
                    <%}%>
                </select>
                <input type="hidden" id="createWareName" value="" name="createWareName">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo'}){}%>
<!-- END 公共脚本 -->
<script>
    var cvalidator;
    $(function(){
        formSelects.render('createSupplierId');
        $('.search-product').on('click',function () {
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var createChannelName=$("#createChannelName").val();
            if(createChannelName==''){
                parent.layer.msg('请先选择渠道！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var createSku=$("#createSku").val();
            if(createSku==''){
                parent.layer.msg('请先填写SKU！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            $.post('/sea/operate/relatedSku/findByChannelSku.do?relatedSku='+createSku+'&relatedChannelName='+createChannelName,function(data){
                if( data.ok ){
                    $("#createFnSku").val(data.data.relatedFnSku);
                    $("#relatedProductName").val(data.data.relatedProductName);
                    $("#createListing").val(data.data.relatedListingName);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });

        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));
        //提交表单
        $('.save-btn').on('click',function(){
            var createSupplierId=formSelects.value('createSupplierId', 'nameStr');
            if(createSupplierId==''){
                parent.layer.msg('请选择供应商！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }else{
                $("#createSupplierName").val(formSelects.value('createSupplierId', 'nameStr'));
            }
            var createWareId = formSelects.value('createWareId','nameStr');
            if(createWareId == ''){
                parent.layer.msg('请选择仓库！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }else{
                $("#createWareName").val(formSelects.value('createWareId', 'nameStr'));
            }
            var createChannelId=$("#createChannelId").val();
            if(createChannelId==''){
                parent.layer.msg('请先选择渠道！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var createSku=$("#createSku").val();
            if(createSku==''){
                parent.layer.msg('请先填写SKU！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var createNumber=$("#createNumber").val();
            if(createNumber==''){
                parent.layer.msg('请填写数量！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var createFnSku=$("#createFnSku").val();
            if(createFnSku==''){
                parent.layer.msg('请检索正确的SKU！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }

            //数据提交
            $.post('/sea/physical/createSku/save.do',$('#info-form').serialize(),function(data){
                if( data.ok ){
                    parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                        parent.$planTable.bootstrapTable('refresh');
                        parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                    });
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                }
            });
        });

        //返回
        $('.return-btn').on('click',function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
        });
    });
</script>
</body>
</html>